package com.acwing.partition35;

import java.io.*;

/**
 * @author rkc
 * @date 2022/8/8 9:11
 */
public class AC3452进制转换 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String s = reader.readLine();
            if (s == null || s.isEmpty()) break;
            boolean neg = s.charAt(0) == '-';
            int ans = 0;
            for (int i = s.length() - 1, j = 0; i > 1 + (neg ? 1 : 0); i--, j++) ans += get(s.charAt(i)) * Math.pow(16, j);
            if (neg) ans *= -1;
            writer.write(ans + "\n");
        }
        writer.flush();
    }

    private static int get(char ch) {
        if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
        if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
        return ch - '0';
    }
}
